package com.loadmore.common.util;

import android.content.Context;
import android.content.SharedPreferences;

import com.loadmore.common.App;

/**
 * Created by sunleilei on 2017/4/23.
 */

public class SharedPreferenceUtil {
    private SharedPreferences sharedPreferences;
    private static SharedPreferenceUtil instance;

    private SharedPreferenceUtil() {
        sharedPreferences = App.getApplication().getSharedPreferences("habit", Context.MODE_PRIVATE);
    }

    public static SharedPreferenceUtil getInstance() {
        if (instance == null) {
            instance = new SharedPreferenceUtil();
        }
        return instance;
    }

    public void putBoolean(String key, boolean value) {
        sharedPreferences.edit().putBoolean(key, value).commit();
    }

    public void putInt(String key, int value) {
        sharedPreferences.edit().putInt(key, value).commit();
    }

    public void putFloat(String key, float value) {
        sharedPreferences.edit().putFloat(key, value).commit();
    }

    public void putString(String key, String value) {
        sharedPreferences.edit().putString(key, value).commit();
    }

    public boolean getBoolean(String key) {
        return sharedPreferences.getBoolean(key, false);
    }

    public int getInt(String key) {
        return sharedPreferences.getInt(key, 0);
    }

    public float getFloat(String key) {
        return sharedPreferences.getFloat(key, 0);
    }

    public String getString(String key) {
        return sharedPreferences.getString(key, "");
    }

}
